<?php
define( 'CACHEDIR' , dirname(__FILE__) . DS . '..' . DS . '..' . DS . 'cache' . DS);
class CacheFile{
	public static function safe_file_put_contents($filename, & $content) {
	    $fp = fopen($filename, 'w+'); 
	    if (!$fp)   return false;
	    if (flock($fp, LOCK_EX))    fwrite($fp, $content); 
	    flock($fp,LOCK_UN); 
	    fclose($fp); 
	    return true; 
	} 
	public static function cacheThumb($newsId,$linkUrl){
		$cacheFile = CACHEDIR.'news'.DS.'newsThumbShell.php';
		$data = array();
		if(is_file($cacheFile)){
			$data = include_once($cacheFile);
 		}else{
			return false;
		}
		$file_content = "<?php return "; 
		$addData = array($newsId=>$linkUrl);
		$newData = $data+$addData;
		array_unique($newData);
		$file_content .= var_export($newData,true).';';
		self::safe_file_put_contents($cacheFile, $file_content);
		return true;
	}

}
